<template>
  <ContentWrap>
    <template #header>
      <div class="card-header">
        <span class="card-title">资源类型统计</span>
      </div>
    </template>
    <div class="card-content">
      <div class="chart" ref="chartRef"></div>
      <div class="chart chart-right">
        <div class="row">
          <div class="cell">数字资源类型</div>
          <div class="cell">数量</div>
          <div class="cell">占比</div>
        </div>
        <div class="row" v-for="(item, index) in dataList" :key="item.namee">
          <div class="cell"><span class="cell-radius" :style="{'background-color': colors[index]}"></span>{{ item.name }}</div>
          <div class="cell color-text">{{ item.value }}个</div>
          <div class="cell color-text">{{ floatNumberFormatter(item.count * 100) }}%</div>
        </div>
      </div>
    </div>
  </ContentWrap>
</template>

<script lang="ts" setup>
import * as echarts from 'echarts'
import { floatNumberFormatter } from '@/utils'
import { ReportApi } from '@/api/dr/report'
const chartRef = shallowRef()
const myChart = shallowRef()
const dataList = ref<any>([
  // { value: 1048, name: '文档' },
  // { value: 735, name: '视频' },
  // { value: 580, name: '图片' },
  // { value: 484, name: '其它' },
])
const colors = ['#948064', '#C3C5AC', '#FF8C46', '#F5EDD9', '#D8C9A7', '#AB9266']
const initChart = () => {
  myChart.value = echarts.init(chartRef.value)
  const option = {
    tooltip: {
      trigger: 'item'
    },
    // legend: {
    //   orient: 'vertical',
    //   right: 'left',
    //   top: 'center'
    // },
    color: colors,
    series: [
      {
        name: '全部资产',
        type: 'pie',
        radius: ['40%', '70%'],
        data: dataList.value,
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  }
  myChart.value.setOption(option)
  window.addEventListener('resize', () => {
    myChart.value.resize()
  })
}
const getData = () => {
  ReportApi.getSourceCount().then((res) => {
    // console.log('getSourceCount', res)
    const list = res.fileTypeDataRespVOS || []
    dataList.value = list.map((item: any) => ({
      value: item.dataNum,
      name: item.dataName,
      count: item.dataCount,
    }))
    initChart() 
  })
}
onMounted(() => {
  getData()
})
</script>

<style lang="scss" scoped>
.card-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .card-title {
    font-weight: bold;
    line-height: 32px;
  }
  .more {
    font-size: 14px;
  }
  :deep(.el-tabs__header) {
    margin: 0;
  }
}
.card-content {
  padding: 0 10px;
  display: flex;
}
.chart {
  width: 55%;
  height: 300px;
}
.chart-right {
  width: 45%;
  height: 300px;
  padding-top: 10px;
  overflow-y: auto;
  .row {
    display: table-row;
  }
  .cell {
    display: table-cell;
    padding: 6px 5px;
  }
  .cell-radius {
    display: inline-block;
    margin-right: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
  }
  .color-text {
    color: #8c8c8c;
  }
}
:deep(.el-card__header) {
  padding: 10px;
}
</style>
